<script type="text/javascript" >
//js语句
	function changenameOnClicked()
	{
		var newname = document.getElementById("newname").value;
		if (newname == "")
		{
			alert("无输入");
			return false;
		}
		if (newname.length < 3 || newname.length > 13)
		{
			alert("长度不符合要求，请重新输入");
			document.getElementById("newname").focus();
			return false;
		}
		if (confirm("你确定要使用" + newname + "作为你的用户名吗?"))
		{
			var postForm = document.createElement("form");//表单对象
			postForm.method = "post";
			postForm.action = 'bonusapp.php';
			var actioninput = document.createElement("input");
			actioninput.setAttribute("name", "action");
			actioninput.setAttribute("value", "changename");
			postForm.appendChild(actioninput);
			var newnameinput = document.createElement("input");
			newnameinput.setAttribute("name", "newname");
			newnameinput.setAttribute("value", newname);
			postForm.appendChild(newnameinput);
			document.body.appendChild(postForm);
			postForm.submit();
			document.body.removeChild(postForm);
		}
		return false;
	}
</script>
<?php
require_once('include/bittorrent.php');
dbconn();
require_once(get_langfile_path());
require(get_langfile_path("", true));
loggedinorreturn();
parked();

function bonusarray($option) {
	global $onegbupload_bonus, $fivegbupload_bonus, $tengbupload_bonus, $hundredgbupload_bonus, $oneinvite_bonus, $customtitle_bonus, $vipstatus_bonus, $basictax_bonus, $taxpercentage_bonus, $bonusnoadpoint_advertisement, $bonusnoadtime_advertisement;
	global $lang_mybonus;
	$bonus = array();
	switch ($option) {
		case 1: {//1.0 GB Uploaded
				$bonus['points'] = $onegbupload_bonus;
				$bonus['art'] = 'traffic';
				$bonus['menge'] = 1073741824;
				$bonus['name'] = $lang_mybonus['text_uploaded_one'];
				$bonus['description'] = $lang_mybonus['text_uploaded_note'];
				break;
			}
		case 2: {//5.0 GB Uploaded
				$bonus['points'] = $fivegbupload_bonus;
				$bonus['art'] = 'traffic';
				$bonus['menge'] = 5368709120;
				$bonus['name'] = $lang_mybonus['text_uploaded_two'];
				$bonus['description'] = $lang_mybonus['text_uploaded_note'];
				break;
			}
		case 3: {//10.0 GB Uploaded
				$bonus['points'] = $tengbupload_bonus;
				$bonus['art'] = 'traffic';
				$bonus['menge'] = 10737418240;
				$bonus['name'] = $lang_mybonus['text_uploaded_three'];
				$bonus['description'] = $lang_mybonus['text_uploaded_note'];
				break;
			}
		case 4: {//100.0 GB Uploaded
				$bonus['points'] = $hundredgbupload_bonus;
				$bonus['art'] = 'traffic';
				$bonus['menge'] = 107374182400;
				$bonus['name'] = "100.0 GB上传量";
				$bonus['description'] = $lang_mybonus['text_uploaded_note'];
				break;
			}
		case 5: {//Invite
				$bonus['points'] = $oneinvite_bonus;
				$bonus['art'] = 'invite';
				$bonus['menge'] = 1;
				$bonus['name'] = $lang_mybonus['text_buy_invite'];
				$bonus['description'] = $lang_mybonus['text_buy_invite_note'];
				break;
			}
		case 6: {//Custom Title
				$bonus['points'] = $customtitle_bonus;
				$bonus['art'] = 'title';
				$bonus['menge'] = 0;
				$bonus['name'] = $lang_mybonus['text_custom_title'];
				$bonus['description'] = $lang_mybonus['text_custom_title_note'];
				break;
			}
		case 7: {//VIP Status
				$bonus['points'] = $vipstatus_bonus;
				$bonus['art'] = 'class';
				$bonus['menge'] = 0;
				$bonus['name'] = $lang_mybonus['text_vip_status'];
				$bonus['description'] = $lang_mybonus['text_vip_status_note'];
				break;
			}
		case 8: {//Bonus Gift
				$bonus['points'] = 25;
				$bonus['art'] = 'gift_1';
				$bonus['menge'] = 0;
				$bonus['name'] = $lang_mybonus['text_bonus_gift'];
				$bonus['description'] = $lang_mybonus['text_bonus_gift_note'];
				if ($basictax_bonus || $taxpercentage_bonus) {
					$onehundredaftertax = 100 - $taxpercentage_bonus - $basictax_bonus;
					$bonus['description'] .= "<br /><br />" . $lang_mybonus['text_system_charges_receiver'] . "<b>" . ($basictax_bonus ? $basictax_bonus . $lang_mybonus['text_tax_bonus_point'] . add_s($basictax_bonus) . ($taxpercentage_bonus ? $lang_mybonus['text_tax_plus'] : "") : "") . ($taxpercentage_bonus ? $taxpercentage_bonus . $lang_mybonus['text_percent_of_transfered_amount'] : "") . "</b>" . $lang_mybonus['text_as_tax'] . $onehundredaftertax . $lang_mybonus['text_tax_example_note'];
				}
				break;
			}
		case 9: {
				$bonus['points'] = $bonusnoadpoint_advertisement;
				$bonus['art'] = 'noad';
				$bonus['menge'] = $bonusnoadtime_advertisement * 86400;
				$bonus['name'] = $bonusnoadtime_advertisement . $lang_mybonus['text_no_advertisements'];
				$bonus['description'] = $lang_mybonus['text_no_advertisements_note'];
				break;
			}
		case 10: {
				$bonus['points'] = 1000;
				$bonus['art'] = 'gift_2';
				$bonus['menge'] = 0;
				$bonus['name'] = $lang_mybonus['text_charity_giving'];
				$bonus['description'] = $lang_mybonus['text_charity_giving_note'];
				break;
			}
		case 11: {//UNInvite
				$bonus['points'] = $oneinvite_bonus * 0.8;
				$bonus['art'] = 'uninvite';
				$bonus['menge'] = 1;
				$bonus['name'] = '出售邀请码';
				$bonus['description'] = '将不需要的邀请码打八折出售换取魔力值。';
				break;
			}
		default: break;
	}
	return $bonus;
}

if ($bonus_tweak == "disable" || $bonus_tweak == "disablesave")
	stderr($lang_mybonus['std_sorry'], $lang_mybonus['std_karma_system_disabled'] . ($bonus_tweak == "disablesave" ? "<b>" . $lang_mybonus['std_points_active'] . "</b>" : ""), false);

$action = htmlspecialchars($_GET['action']);
$do = htmlspecialchars($_GET['do']);
unset($msg);
if (isset($do)) {
	if ($do == "upload")
		$msg = $lang_mybonus['text_success_upload'];
	elseif ($do == "invite")
		$msg = $lang_mybonus['text_success_invites'];
	elseif ($do == "vip")
		$msg = $lang_mybonus['text_success_vip'] . "<b>" . get_user_class_name_zh(UC_VIP, false, false, true) . "</b>" . $lang_mybonus['text_success_vip_two'];
	elseif ($do == "vipfalse")
		$msg = $lang_mybonus['text_no_permission'];
	elseif ($do == "title")
		$msg = $lang_mybonus['text_success_custom_title'];
	elseif ($do == "transfer")
		$msg = $lang_mybonus['text_success_gift'];
	elseif ($do == "noad")
		$msg = $lang_mybonus['text_success_no_ad'];
	elseif ($do == "charity")
		$msg = $lang_mybonus['text_success_charity'];
	elseif ($do == "uninvite")
		$msg = "出售邀请码成功，你失去了一个邀请码，获得了" . $oneinvite_bonus * 0.8 . "个魔力值。";
	else
		$msg = '';
}
stdhead($CURUSER['username'] . $lang_mybonus['head_karma_page']);

$bonus = number_format((int) $CURUSER['seedbonus'], 0);
if (!$action) {
	print("<table align=\"center\" width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n");
	print("<tr><td class=\"colhead\" colspan=\"4\" align=\"center\"><font class=\"big\">" . $SITENAME . $lang_mybonus['text_karma_system'] . "</font></td></tr>\n");
	if ($msg)
		print("<tr><td align=\"center\" colspan=\"4\"><font class=\"striking\">" . $msg . "</font></td></tr>");
	?>
	<tr><td class="text" align="center" colspan="4"><?php echo $lang_mybonus['text_exchange_your_karma'] ?><?php echo $bonus ?><?php echo $lang_mybonus['text_for_goodies'] ?>
			<br /><b><?php echo $lang_mybonus['text_no_buttons_note'] ?></b></td></tr>
	<?php
	print("<tr><td class=\"colhead\" align=\"center\">" . $lang_mybonus['col_option'] . "</td>" .
			"<td class=\"colhead\" align=\"left\">" . $lang_mybonus['col_description'] . "</td>" .
			"<td class=\"colhead\" align=\"center\">" . $lang_mybonus['col_points'] . "</td>" .
			"<td class=\"colhead\" align=\"center\">" . $lang_mybonus['col_trade'] . "</td>" .
			"</tr>");
	for ($i = 1; $i <= 12; $i++) {
		$bonusarray = bonusarray($i);
		if (($i == 8 && $bonusgift_bonus == 'no') || ($i == 9 && ($enablead_advertisement == 'no' || $bonusnoad_advertisement == 'no')))
			continue;
		print("<tr>");
		print("<form action=\"?action=exchange\" method=\"post\">");
		print("<td class=\"rowhead_center\"><input type=\"hidden\" name=\"option\" value=\"" . $i . "\" /><b>" . $i . "</b></td>");
		if ($i == 6) {//for Custom Title!
			$otheroption_title = "<input type=\"text\" name=\"title\" style=\"width: 200px\" maxlength=\"30\" />";
			print("<td class=\"rowfollow\" align='left'><h1>" . $bonusarray['name'] . "</h1>" . $bonusarray['description'] . "<br /><br />" . $lang_mybonus['text_enter_titile'] . $otheroption_title . $lang_mybonus['text_click_exchange'] . "</td><td class=\"rowfollow\" align='center'>" . number_format($bonusarray['points']) . "</td>");
		} elseif ($i == 8) {//for Give A Karma Gift
			$otheroption = "<table width=\"100%\"><tr><td class=\"embedded\"><b>" . $lang_mybonus['text_username'] . "</b><input type='hidden' name='where' value=\"[url=mybonus.php]魔力值使用[/url]\"/><input type=\"text\" name=\"username\" style=\"width: 400px\" maxlength=\"24\" /></td><td class=\"embedded\"><b>" . $lang_mybonus['text_to_be_given'] . "</b><select name=\"bonusgift\" id=\"giftselect\" onchange=\"customgift();\"> <option value=\"25\"> 25</option><option value=\"50\"> 50</option><option value=\"100\"> 100</option> <option value=\"200\"> 200</option> <option value=\"300\"> 300</option> <option value=\"400\"> 400</option><option value=\"500\"> 500</option><option value=\"1000\" selected=\"selected\"> 1,000</option><option value=\"5000\"> 5,000</option><option value=\"10000\"> 10,000</option><option value=\"0\">" . $lang_mybonus['text_custom'] . "</option></select><input type=\"text\" name=\"bonusgift\" id=\"giftcustom\" style='width: 80px' disabled=\"disabled\" />" . $lang_mybonus['text_karma_points'] . "</td></tr><tr><td class=\"embedded\" colspan=\"2\"><b>" . $lang_mybonus['text_message'] . "</b><input type=\"text\" name=\"message\" style=\"width: 610px\" maxlength=\"100\" /></td></tr></table>";
			print("<td class=\"rowfollow\" align='left'><h1>" . $bonusarray['name'] . "</h1>" . $bonusarray['description'] . "<br /><br />" . $lang_mybonus['text_enter_receiver_name'] . "<br />$otheroption</td><td class=\"rowfollow nowrap\" align='center'>" . $lang_mybonus['text_min'] . "25<br />" . $lang_mybonus['text_max'] . "10,000</td>");
		} elseif ($i == 10) {//charity giving
			$otheroption = "<table width=\"100%\"><tr><td class=\"embedded\">" . $lang_mybonus['text_ratio_below'] . "<select name=\"ratiocharity\"> <option value=\"0.1\"> 0.1</option><option value=\"0.2\"> 0.2</option><option value=\"0.3\" selected=\"selected\"> 0.3</option> <option value=\"0.4\"> 0.4</option> <option value=\"0.5\"> 0.5</option> <option value=\"0.6\"> 0.6</option><option value=\"0.7\"> 0.7</option><option value=\"0.8\"> 0.8</option></select>" . $lang_mybonus['text_and_downloaded_above'] . " 10 GB</td><td class=\"embedded\"><b>" . $lang_mybonus['text_to_be_given'] . "</b><select name=\"bonuscharity\" id=\"charityselect\" > <option value=\"1000\"> 1,000</option><option value=\"2000\"> 2,000</option><option value=\"3000\" selected=\"selected\"> 3,000</option> <option value=\"5000\"> 5,000</option> <option value=\"8000\"> 8,000</option> <option value=\"10000\"> 10,000</option><option value=\"20000\"> 20,000</option><option value=\"50000\"> 50,000</option></select>" . $lang_mybonus['text_karma_points'] . "</td></tr></table>";
			print("<td class=\"rowfollow\" align='left'><h1>" . $bonusarray['name'] . "</h1>" . $bonusarray['description'] . "<br /><br />" . $lang_mybonus['text_select_receiver_ratio'] . "<br />$otheroption</td><td class=\"rowfollow nowrap\" align='center'>" . $lang_mybonus['text_min'] . "1,000<br />" . $lang_mybonus['text_max'] . "50,000</td>");
		} elseif ($i == 12) {
			$row = mysql_fetch_array(sql_query("SELECT namecharge FROM bonusapp WHERE userid = $CURUSER[id]"));
			$namecharge = $row['namecharge'];
			if (empty($namecharge)) {
				$namecharge = 10000;
			} elseif ($namecharge >= 100000) {
				$namecharge = 100000;
			}
			print("<td><h1>改头换面</h1>如果你觉得自己名字不好听或者因为其他原因需要改名字，那么你可以使用你的魔力值换取一个改名字的机会。<br>提示：第一次价格为1万，每一次修改都是上一次的2倍，最高10万。<br>只允许中文、字母、数字，4至14个字符<br>在此输入新名字<input type=\"text\" name=\"newname\" id=\"newname\" style='width: 160px' /></td><td align=center>" . number_format($namecharge) . "</td>");
		} elseif ($i == 11) {
			print("<td class=\"rowfollow\" align='left'><h1>" . $bonusarray['name'] . "</h1>" . $bonusarray['description'] . "</td><td class=\"rowfollow\" align='center'>获得" . number_format($bonusarray['points']) . "</td>");
		} else {//for VIP or Upload
			print("<td class=\"rowfollow\" align='left'><h1>" . $bonusarray['name'] . "</h1>" . $bonusarray['description'] . "</td><td class=\"rowfollow\" align='center'>" . number_format($bonusarray['points']) . "</td>");
		}

		if ($i == 11) {
			if (get_user_class() >= $prfmanage_class) {
				print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_exchange'] . "\" /></td>");
			} else {
				print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_exchange'] . "\" disabled /></td>");
			}
		} elseif ($CURUSER['seedbonus'] >= $bonusarray['points']) {
			if ($i == 8) {
				print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_karma_gift'] . "\" /></td>");
			} elseif ($i == 9) {
				if ($enablenoad_advertisement == 'yes' && get_user_class() >= $noad_advertisement) {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_class_above_no_ad'] . "\" disabled=\"disabled\" /></td>");
				} elseif (strtotime($CURUSER['noaduntil']) >= TIMENOW) {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_already_disabled'] . "\" disabled=\"disabled\" /></td>");
				} elseif (get_user_class() < $bonusnoad_advertisement) {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . get_user_class_name_zh($bonusnoad_advertisement, false, false, true) . $lang_mybonus['text_plus_only'] . "\" disabled=\"disabled\" /></td>");
				} else {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_exchange'] . "\" /></td>");
				}
			} elseif ($i == 10) {
				print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_charity_giving'] . "\" /></td>");
			} elseif ($i == 5) {
				if (get_user_class() < $buyinvite_class)
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . get_user_class_name_zh($buyinvite_class, false, false, true) . $lang_mybonus['text_plus_only'] . "\" disabled=\"disabled\" /></td>");
				else
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_exchange'] . "\" /></td>");
			} elseif ($i == 12) {
				if ($CURUSER['seedbonus'] >= $namecharge) {
					echo "<td class=\"rowfollow\" align=\"center\"><input type=button onclick=changenameOnClicked() value='改名'/></td>";
				} else {
					echo "<td class=\"rowfollow\" align=\"center\"><input type=button onclick=changenameOnClicked() value='需要更多魔力值' disabled/></td>";
				}
			} elseif ($i == 7) {
				if (get_user_class() >= UC_VIP) {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['std_class_above_vip'] . "\" disabled=\"disabled\" /></td>");
				} else {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_exchange'] . "\" /></td>");
				}
			} elseif ($i == 6) {
				print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_exchange'] . "\" /></td>");
			} else {
				if ($CURUSER['downloaded'] > 0) {
					if ($CURUSER['uploaded'] > $dlamountlimit_bonus * 1073741824) {//Uploaded amount reach limit
						$ratio = $CURUSER['uploaded'] / $CURUSER['downloaded'];
					} else {
						$ratio = 0;
					}
				} else {
					$ratio = $ratiolimit_bonus + 1; //Ratio always above limit
				}
				if ($ratiolimit_bonus > 0 && $ratio > $ratiolimit_bonus) {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['text_ratio_too_high'] . "\" disabled=\"disabled\" /></td>");
				} elseif ($assessment == 'yes' && $assessmentconvert == 'yes' && get_user_class() < $assessmentmanage) {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['text_convert_off'] . "\" disabled=\"disabled\" /></td>");
				} else {
					print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['submit_exchange'] . "\" /></td>");
				}
			}
		} else {
			print("<td class=\"rowfollow\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"" . $lang_mybonus['text_more_points_needed'] . "\" disabled=\"disabled\" /></td>");
		}
		print("</form>");
		print("</tr>");
	}
	print("</table><br />");
	?>

	<table width="90%" cellpadding="3">
		<tr><td class="colhead" align="center"><font class="big"><?php echo $lang_mybonus['text_what_is_karma'] ?></font></td></tr>
		<tr><td class="text" align="left">
				<?php
				print("<h1>" . $lang_mybonus['text_get_by_updown'] . "</h1>");
				print("<ul>");
				print("<li>" . $lang_mybonus['text_upload'] . "</li>");
				print("<li>" . $lang_mybonus['text_down'] . "</li>");
				print("</ul>");
				print("<h1>" . $lang_mybonus['text_get_by_seeding'] . "</h1>");
				print("<ul>");
				if ($perseeding_bonus > 0) {
					print("<li>" . $perseeding_bonus . $lang_mybonus['text_point'] . add_s($perseeding_bonus) . $lang_mybonus['text_for_seeding_torrent'] . $maxseeding_bonus . $lang_mybonus['text_torrent'] . add_s($maxseeding_bonus) . ")</li>");
				}
				print("<li>" . $lang_mybonus['text_bonus_formula_one'] . $tzero_bonus . $lang_mybonus['text_bonus_formula_two'] . $nzero_bonus . $lang_mybonus['text_bonus_formula_three'] . $bzero_bonus . $lang_mybonus['text_bonus_formula_four'] . $l_bonus . $lang_mybonus['text_bonus_formula_five'] . "</li>");
				if ($donortimes_bonus > 0) {
					print("<li>" . $lang_mybonus['text_donors_always_get'] . $donortimes_bonus . $lang_mybonus['text_times_of_bonus'] . "</li>");
				}
				print("</ul>");
				//做种积分算法--开始
				//参数部分--开始
				$pi = 3.141592653589793;
				$class = $CURUSER['class'];
				switch ($class) {
					case UC_POWER_USER:
						$rate = "1.15";
						break;
					case UC_ELITE_USER:
						$rate = "1.2";
						break;
					case UC_CRAZY_USER:
						$rate = "1.25";
						break;
					case UC_INSANE_USER:
						$rate = "1.3";
						break;
					case UC_VETERAN_USER:
						$rate = "1.35";
						break;
					case UC_EXTREME_USER:
						$rate = "1.4";
						break;
					case UC_ULTIMATE_USER:
						$rate = "1.45";
						break;
					case UC_NEXUS_MASTER:
						$rate = "1.5";
						break;
					default :
						$rate = "1.1";
				}
				if ($class >= UC_VIP) {
					$rate = "1.6";
				}
				$timenow = time();
				$sectoweek = 86400 * 7;
				$count = 0;
				$sqrtof2 = sqrt(2);
				$logofpointone = log(0.1);
				$value1 = $logofpointone / $tzero_bonus; //T0
				$value2 = $bzero_bonus * ( 2 / $pi); //B0
				$value3 = $logofpointone / ($nzero_bonus - 1); //N0
				$value4 = $l_bonus; //L
				$A = 0;
				//参数部分--结束
				$torrentres = sql_query("SELECT torrents.id, torrents.added, torrents.size, torrents.seeders, (SELECT COUNT(*) FROM torrents WHERE official = 'yes') AS official FROM torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = $CURUSER[id] AND peers.seeder = 'yes' GROUP BY torrents.id") or sqlerr(__FILE__, __LINE__);
				while ($torrent = mysql_fetch_array($torrentres)) {
					$weeks_alive = ($timenow - strtotime($torrent['added'])) / $sectoweek;
					$gb_size = $torrent['size'] / 1073741824;
					if ($torrent['official'] > 0) {
						$official = $torrent['official'];
					} else {
						$official = 0;
					}
					$temp = (1 - exp($value1 * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($value3 * ($torrent['seeders'] - 1))) + $official * 0.5;
					$A += $temp;
					$count++;
				}
				if ($count > $maxseeding_bonus) {//固定获取魔力值
					$count = $maxseeding_bonus;
				}
				if ($A != 0) {
					$all_bonus = ($value2 * atan($A / $value4) + ($perseeding_bonus * $count)) * $rate;
				} else {
					$all_bonus = 0;
				}
				$percent = $all_bonus * 100 / ($bzero_bonus + $perseeding_bonus * $maxseeding_bonus);
				if ($is_donor['donor'] == 'yes' && $donortimes_bonus > 0) {
					print("<div align=\"center\">" . $lang_mybonus['text_you_are_currently_getting'] . "(" . round($all_bonus, 3) . ")" . round($all_bonus * $donortimes_bonus, 3) . $lang_mybonus['text_point'] . add_s($all_bonus) . $lang_mybonus['text_per_hour'] . " (A = " . round($A, 1) . ")</div><table align=\"center\" border=\"0\" width=\"400\"><tr><td class=\"loadbarbg\" style='border: none; padding: 0px;'>");
				} else {
					print("<div align=\"center\">" . $lang_mybonus['text_you_are_currently_getting'] . round($all_bonus, 3) . $lang_mybonus['text_point'] . add_s($all_bonus) . $lang_mybonus['text_per_hour'] . " (A = " . round($A, 1) . ")</div><table align=\"center\" border=\"0\" width=\"400\"><tr><td class=\"loadbarbg\" style='border: none; padding: 0px;'>");
				}
				if ($percent <= 30) {
					$loadpic = "loadbarred";
				} elseif ($percent <= 60) {
					$loadpic = "loadbaryellow";
				} else {
					$loadpic = "loadbargreen";
				}
				$width = $percent * 5;
				print("<img class=\"" . $loadpic . "\" src=\"pic/trans.gif\" style=\"width: " . $width . "px;\" alt=\"" . $percent . "%\" /></td></tr></table>"); //进度条
				//做种积分算法--结束
				print("<h1>" . $lang_mybonus['text_other_things_get_bonus'] . "</h1>");
				print("<ul>");
				if ($uploadtorrent_bonus > 0)
					print("<li>" . $lang_mybonus['text_upload_torrent'] . $uploadtorrent_bonus . $lang_mybonus['text_point'] . add_s($uploadtorrent_bonus) . "</li>");
				if ($uploadsubtitle_bonus > 0)
					print("<li>" . $lang_mybonus['text_upload_subtitle'] . $uploadsubtitle_bonus . $lang_mybonus['text_point'] . add_s($uploadsubtitle_bonus) . "</li>");
				if ($starttopic_bonus > 0)
					print("<li>" . $lang_mybonus['text_start_topic'] . $starttopic_bonus . $lang_mybonus['text_point'] . add_s($starttopic_bonus) . "</li>");
				if ($makepost_bonus > 0)
					print("<li>" . $lang_mybonus['text_make_post'] . $makepost_bonus . $lang_mybonus['text_point'] . add_s($makepost_bonus) . "</li>");
				if ($addcomment_bonus > 0)
					print("<li>" . $lang_mybonus['text_add_comment'] . $addcomment_bonus . $lang_mybonus['text_point'] . add_s($addcomment_bonus) . "</li>");
				if ($pollvote_bonus > 0)
					print("<li>" . $lang_mybonus['text_poll_vote'] . $pollvote_bonus . $lang_mybonus['text_point'] . add_s($pollvote_bonus) . "</li>");
				if ($offervote_bonus > 0)
					print("<li>" . $lang_mybonus['text_offer_vote'] . $offervote_bonus . $lang_mybonus['text_point'] . add_s($offervote_bonus) . "</li>");
				if ($funboxvote_bonus > 0)
					print("<li>" . $lang_mybonus['text_funbox_vote'] . $funboxvote_bonus . $lang_mybonus['text_point'] . add_s($funboxvote_bonus) . "</li>");
				if ($ratetorrent_bonus > 0)
					print("<li>" . $lang_mybonus['text_rate_torrent'] . $ratetorrent_bonus . $lang_mybonus['text_point'] . add_s($ratetorrent_bonus) . "</li>");
				if ($saythanks_bonus > 0)
					print("<li>" . $lang_mybonus['text_say_thanks'] . $saythanks_bonus . $lang_mybonus['text_point'] . add_s($saythanks_bonus) . "</li>");
				if ($receivethanks_bonus > 0)
					print("<li>" . $lang_mybonus['text_receive_thanks'] . $receivethanks_bonus . $lang_mybonus['text_point'] . add_s($receivethanks_bonus) . "</li>");
				if ($adclickbonus_advertisement > 0)
					print("<li>" . $lang_mybonus['text_click_on_ad'] . $adclickbonus_advertisement . $lang_mybonus['text_point'] . add_s($adclickbonus_advertisement) . "</li>");
				if ($prolinkpoint_bonus > 0)
					print("<li>" . $lang_mybonus['text_promotion_link_clicked'] . $prolinkpoint_bonus . $lang_mybonus['text_point'] . add_s($prolinkpoint_bonus) . "</li>");
				if ($funboxreward_bonus > 0)
					print("<li>" . $lang_mybonus['text_funbox_reward'] . "</li>");
				print($lang_mybonus['text_howto_get_karma_four']);
				if ($ratiolimit_bonus > 0)
					print("<li>" . $lang_mybonus['text_user_with_ratio_above'] . $ratiolimit_bonus . $lang_mybonus['text_and_uploaded_amount_above'] . $dlamountlimit_bonus . $lang_mybonus['text_cannot_exchange_uploading'] . "</li>");
				print($lang_mybonus['text_howto_get_karma_five'] . $uploadtorrent_bonus . $lang_mybonus['text_point'] . add_s($uploadtorrent_bonus) . $lang_mybonus['text_howto_get_karma_six']);
				?>
			</td></tr></table>
	<?php
}


// Bonus exchange
if ($action == "exchange") {
	if ($_POST["userid"] || $_POST["points"] || $_POST["bonus"] || $_POST["art"]) {
		write_log("User " . $CURUSER["username"] . "，IP " . $CURUSER["ip"] . " 试图欺骗魔力值系统", 'mod');
		die($lang_mybonus['text_cheat_alert']);
	}
	$option = (int) $_POST["option"];
	$bonusarray = bonusarray($option);
	$points = $bonusarray['points'];
	$userid = $CURUSER['id'];
	$art = $bonusarray['art'];
	$bonuscomment = $CURUSER['bonuscomment'];
	$seedbonus = $CURUSER['seedbonus'] - $points;
	if ($art == "uninvite") {
		/*
		  if (get_user_class() < $buyinvite_class)
		  die(get_user_class_name_zh($buyinvite_class, false, false, true) . $lang_mybonus['text_plus_only']);
		 *
		 */
		$invites = $CURUSER['invites'];
		if ($invites == 0) {
			die("你的邀请码不足");
		}
		if ($CURUSER['class'] < $prfmanage_class) {
			if ($CURUSER['added'] > date("Y-m-d H:i:s", time() - 86400 * 30)) {
				die("注册时间不足30天，无法将不需要的邀请码兑换成魔力值");
			} else {
				die("非管理员不允许出售邀请码");
			}
		}
		$inv = $invites - $bonusarray['menge'];
		$bonuscomment = date("Y-m-d H:i:s") . " - 出售一个邀请码获得 + " . $points . " 魔力值\n" . htmlspecialchars($bonuscomment);
		if ($CURUSER['invites'] > 0) {
			sql_query("UPDATE users SET invites = " . sqlesc($inv) . ", seedbonus = seedbonus + $points, bonuscomment = " . sqlesc($bonuscomment) . "  WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
		} else {
			sql_query("UPDATE users SET seedbonus = seedbonus + $points, bonuscomment = " . sqlesc($bonuscomment) . "  WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
		}
		redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=uninvite");
	} elseif ($CURUSER['seedbonus'] >= $points) {
//=== trade for upload
		if ($art == "traffic") {
			if ($CURUSER['uploaded'] > $dlamountlimit_bonus * 1073741824)//uploaded amount reach limit
				$ratio = $CURUSER['uploaded'] / $CURUSER['downloaded'];
			else
				$ratio = 0;
			if ($ratiolimit_bonus > 0 && $ratio > $ratiolimit_bonus)
				die($lang_mybonus['text_cheat_alert']);
			else {
				$upload = $CURUSER['uploaded'];
				$up = $upload + $bonusarray['menge'];
				$bonuscomment = date("Y-m-d H:i:s") . " - 使用 " . $points . " 魔力值兑换上传量\n" . $bonuscomment;
				sql_query("UPDATE users SET uploaded = " . sqlesc($up) . ", seedbonus = seedbonus - $points, bonuscomment = " . sqlesc($bonuscomment) . " WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
				redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=upload");
			}
		}
//=== trade for one month VIP status ***note "SET class = '10'" change "10" to whatever your VIP class number is
		elseif ($art == "class") {
			if (get_user_class() >= UC_VIP) {
				stdmsg($lang_mybonus['std_no_permission'], $lang_mybonus['std_class_above_vip'], 0);
				stdfoot();
				die;
			}
			if ($CURUSER['added'] > date("Y-m-d H:i:s", time() - 86400 * 30)) {
				die("注册时间不足30天，无法兑换VIP权限");
			}
			$vip_until = date("Y-m-d H:i:s", (strtotime(date("Y-m-d H:i:s")) + 7 * 86400));
			$bonuscomment = date("Y-m-d H:i:s") . " - 使用 " . $points . " 魔力值兑换一星期VIP权限\n" . htmlspecialchars($bonuscomment);
			sql_query("UPDATE users SET tovip = '" . $CURUSER['class'] . "', class = '" . UC_VIP . "', vip_added = 'yes', vip_until = " . sqlesc($vip_until) . ", seedbonus = seedbonus - $points WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
			redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=vip");
		}
//=== trade for invites
		elseif ($art == "invite") {
			if (get_user_class() < $buyinvite_class)
				die(get_user_class_name_zh($buyinvite_class, false, false, true) . $lang_mybonus['text_plus_only']);
			$invites = $CURUSER['invites'];
			$inv = $invites + $bonusarray['menge'];
			$bonuscomment = date("Y-m-d H:i:s") . " - 购买一个邀请码消费 " . $points . " 魔力值\n" . htmlspecialchars($bonuscomment);
			sql_query("UPDATE users SET invites = " . sqlesc($inv) . ", seedbonus = seedbonus - $points, bonuscomment = " . sqlesc($bonuscomment) . "  WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
			redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=invite");
		}
//=== trade for special title
		/*		 * ** the $words array are words that you DO NOT want the user to have... use to filter "bad words" & user class...
		  the user class is just for show, but what the hell tongue.gif Add more or edit to your liking.
		 * note if they try to use a restricted word, they will recieve the special title "I just wasted my karma" **** */ elseif ($art == "title") {
//===custom title
			$words = array("fuck", "shit", "pussy", "cunt", "nigger", "Staff Leader", "SysOp", "Administrator", "Moderator", "Uploader", "Retiree", "VIP", "Nexus Master", "Ultimate User", "Extreme User", "Veteran User", "Insane User", "Crazy User", "Elite User", "Power User", "User", "Peasant", "Champion");
			if ($CURUSER['title'] == '' && $_POST["title"] == '') {
				stdmsg("错误", "自定义头衔不可为空！");
				stdfoot();
				exit;
			}
			$title = str_replace($words, $lang_mybonus['text_wasted_karma'], sqlesc($_POST["title"]));
			$bonuscomment = date("Y-m-d H:i:s") . " - 使用 " . $points . " 魔力值兑换了一个称号。旧称号 " . htmlspecialchars(trim($CURUSER["title"])) . " 改为 $title\n" . htmlspecialchars($bonuscomment);
			sql_query("UPDATE users SET title = $title, seedbonus = seedbonus - $points, bonuscomment = " . sqlesc($bonuscomment) . " WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
			if ($_POST["title"] != '') {
				sendshoutbox("[@$CURUSER[username]] 换了一个新的自定义称号叫[b]“{$title}”[/b]，真是高端大气上档次，快来围观啊づ￣ 3￣)づ");
			}
			redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=title");
		} elseif ($art == "noad" && $enablead_advertisement == 'yes' && $enablebonusnoad_advertisement == 'yes') {
			if (($enablenoad_advertisement == 'yes' && get_user_class() >= $noad_advertisement) || strtotime($CURUSER['noaduntil']) >= TIMENOW || get_user_class() < $bonusnoad_advertisement)
				die($lang_mybonus['text_cheat_alert']);
			else {
				$noaduntil = date("Y-m-d H:i:s", (TIMENOW + $bonusarray['menge']));
				$bonuscomment = date("Y-m-d H:i:s") . " - 使用 " . $points . " 魔力值兑换了 " . $bonusnoadtime_advertisement . " 天无广告\n" . htmlspecialchars($bonuscomment);
				sql_query("UPDATE users SET noad='yes', noaduntil = '" . $noaduntil . "', seedbonus = seedbonus - $points, bonuscomment = " . sqlesc($bonuscomment) . " WHERE id=" . sqlesc($userid));
				redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=noad");
			}
		} elseif ($art == 'gift_2') { // charity giving
			$points = 0 + $_POST["bonuscharity"];
			if ($points < 1000 || $points > 50000) {
				stdmsg($lang_mybonus['text_error'], $lang_mybonus['bonus_amount_not_allowed_two'], 0);
				stdfoot();
				die();
			}
			$ratiocharity = 0.0 + $_POST["ratiocharity"];
			if ($ratiocharity < 0.1 || $ratiocharity > 0.8) {
				stdmsg($lang_mybonus['text_error'], $lang_mybonus['bonus_ratio_not_allowed']);
				stdfoot();
				die();
			}
			if ($CURUSER['seedbonus'] >= $points) {
				$points2 = number_format($points, 1);
				$bonuscomment = date("Y-m-d H:i:s") . " - 使用 " . $points2 . " 魔力值赠送给分享率低于 " . htmlspecialchars(trim($ratiocharity)) . " 的用户\n" . htmlspecialchars($bonuscomment);
				$charityReceiverCount = get_row_count("users", "WHERE enabled='yes' AND 10737418240 < downloaded AND $ratiocharity > uploaded/downloaded");
				if ($charityReceiverCount) {
					sql_query("UPDATE users SET seedbonus = seedbonus - $points, charity = charity + $points, bonuscomment = " . sqlesc($bonuscomment) . " WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
					$charityPerUser = $points / $charityReceiverCount;
					sql_query("UPDATE users SET seedbonus = seedbonus + $charityPerUser WHERE enabled='yes' AND 10737418240 < downloaded AND $ratiocharity > uploaded/downloaded") or sqlerr(__FILE__, __LINE__);
					sendshoutbox("[@$CURUSER[username]] 给分享率低于 $ratiocharity 的用户赠送了 $points 个魔力值，简直是菩萨再世，快来跪拜啊跪拜啊啊啊啊乀(ˉεˉ乀)");
					redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=charity");
				} else {
					stdmsg($lang_mybonus['std_sorry'], $lang_mybonus['std_no_users_need_charity']);
					stdfoot();
					die;
				}
			}
		} elseif ($art == "gift_1" && $bonusgift_bonus == 'yes') {
//=== trade for giving the gift of karma
			$points = 0 + $_POST["bonusgift"];
			$message = $_POST["message"];
//==gift for peeps with no more options以下
			$usernamegift = explode(",", $_POST["username"]);
			$count = count($usernamegift);
			$added = sqlesc(date("Y-m-d H:i:s")); //$postid = $_POST['postsid'] + 0;
			$postidarr = explode(",", $_POST["postsid"]);
			for ($i = 0; $i < $count; $i++) {
//$usernamegift[$i] = sqlesc(trim($usernamegift[$i]));
				$arr = mysql_fetch_assoc(sql_query("SELECT id, bonuscomment FROM users WHERE username=" . sqlesc($usernamegift[$i])));
				if (!$arr) {
					echo "<script type='text/javascript'> alert('用户名出错，请重新输入!');history.go(-1) </script>";
					die;
				}
			}

//$usernamegift = sqlesc(trim($_POST["username"]));以上
//$res = sql_query("SELECT id, bonuscomment FROM users WHERE username=" . $usernamegift);
//$arr = mysql_fetch_assoc($res);
			if ($points < 25 || $points > 10000) {
//write_log("User " . $CURUSER["username"] . "," . $CURUSER["ip"] . " is hacking bonus system",'mod');
				stdmsg($lang_mybonus['text_error'], $lang_mybonus['bonus_amount_not_allowed']);
				stdfoot();
				die();
			}
			$userseedbonusnow = $CURUSER['seedbonus'];
			for ($i = 0; $i < $count; $i++) {
//$useridgift[$i] = $arr[id];
				$arr = mysql_fetch_assoc(sql_query("SELECT id, bonuscomment FROM users WHERE username=" . sqlesc($usernamegift[$i])));
//$userseedbonus = $arr['seedbonus'];
				$receiverbonuscomment = $arr['bonuscomment'];
//$usernamegift[$i] = sqlesc($usernamegift[$i]);

				if ($userseedbonusnow >= $points) {
					$points2 = number_format($points, 1);
					$bonuscomment = date("Y-m-d H:i:s") . " - " . $points2 . " 个魔力值，送给了 " . $usernamegift[$i] . "\n" . htmlspecialchars($bonuscomment);
					$userseedbonusnow -= $points;
					$aftertaxpoint = $points;
					if ($taxpercentage_bonus)
						$aftertaxpoint -= $aftertaxpoint * $taxpercentage_bonus * 0.01;
					if ($basictax_bonus)
						$aftertaxpoint -= $basictax_bonus;

					$points2receiver = number_format($aftertaxpoint, 1);
					$newreceiverbonuscomment = date("Y-m-d H:i:s") . " + " . $points2receiver . " 个魔力值（税后），来自：" . ($CURUSER["username"]) . "\n" . htmlspecialchars($receiverbonuscomment);
					/*
					  if ($userid == $arr[id]) {
					  stdmsg($lang_mybonus['text_huh'], $lang_mybonus['text_karma_self_giving_warning'], 0);
					  stdfoot();
					  die;
					  }
					  if (!$arr[id]) {
					  stdmsg($lang_mybonus['text_error'], $lang_mybonus['text_receiver_not_exists'], 0);
					  stdfoot();
					  die;
					  }
					 *
					 */

					sql_query("UPDATE users SET seedbonus = seedbonus - $points, bonuscomment = " . sqlesc($bonuscomment) . " WHERE id = " . sqlesc($userid)) or sqlerr(__FILE__, __LINE__);
					if ($arr[id] == $robot) {
						$addup = $points * 2000000;
						$adddown = $addup / 4;
						$newreceiverbonuscomment = date("Y-m-d H:i:s") . " + " . $points2receiver . " 个魔力值（税后），来自：" . ($CURUSER[username]) . " 把TA们变成了上传下载量，努力升级~\n" . htmlspecialchars($receiverbonuscomment);
						sql_query("UPDATE users SET  bonuscomment = " . sqlesc($newreceiverbonuscomment) . ", last_access=now() , last_login=now(), uploaded = uploaded + $addup , downloaded = downloaded + $adddown WHERE id = " . sqlesc($arr[id])) or sqlerr(__FILE__, __LINE__);
						$addup = mksize($addup);
						$adddown = mksize($adddown);
						sendshoutbox("亲爱的 [@$CURUSER[username]] 送了 $points 个魔力值给我（¯﹃¯） ，爱死你了~我增长了 $addup 上传和 $adddown 下载，我要努力升级，我可是要当太监总管的机器人ノ￣ー￣)ノ");
					} else
						sql_query("UPDATE users SET seedbonus = seedbonus + $aftertaxpoint, bonuscomment = " . sqlesc($newreceiverbonuscomment) . " WHERE id = " . sqlesc($arr[id])) or sqlerr(__FILE__, __LINE__);

//为saythanks开辟的渠道 start SamuraiMe,2013.05.19
					if (isset($_POST["torrent_id"])) {
						$ch = curl_init();
						$res = sql_query("INSERT INTO thanks (torrentid, userid, bonus) VALUES (" . sqlesc($_POST["torrent_id"]) . ", " . sqlesc($CURUSER['id']) . ", " . sqlesc($points) . ")");
					}
//为saythanks开辟的渠道 end SamuraiMe,2013.05.19
//为论坛添加赠送魔力值显示
					if ($postidarr[$i] != 0) {
						$postarr = array('info' => $CURUSER['username'] . " 于 " . date("Y-m-d H:i:s") . " 赠送给 " . $usernamegift[$i] . " " . $points . " 魔力值" . "<br />");
						sql_query("UPDATE posts SET sendlog = CONCAT(sendlog, " . sqlesc(implode($postarr)) . ") WHERE id = " . $postidarr[$i]);
					}
//===send message
					if ($_POST['where']) {
						$where = $_POST['where'];
					} else
						$where = "[b]未知页面[/b]（请向管理员反映此错误）";
					$wheremsg = "发信者[b]" . $CURUSER['username'] . "[/b]在" . $where . "中为您赠送礼物，";
					$subject = sqlesc("收到礼物");
					$msg = $wheremsg . "你收到" . $points2 . "个魔力值（扣除手续费后为" . $points2receiver . "）个魔力值作为礼物。祝福来自" . $CURUSER['username'] . "，此信息由系统代替用户发送。";
					if ($message)
						$msg .= "\n" . $CURUSER['username'] . "说：" . $message;
					$msg = sqlesc($msg);
					sql_query("INSERT INTO messages (sender, subject, receiver, msg, added) VALUES({$CURUSER['id']}, $subject, {$arr['id']}, $msg, $added)") or sqlerr(__FILE__, __LINE__);
//$usernamegift = unesc($_POST["username"]);
//redirect("" . get_protocol_prefix() . "$BASEURL/mybonus.php?do=transfer");
					echo "成功送给 <b>$usernamegift[$i]</b><i>$points</i>魔力值<br/>";
				}

				else {
					print("<table width=\"940\"><tr><td class=\"colhead\" align=\"left\" colspan=\"2\"><h1>" . $lang_mybonus['text_oups'] . "</h1></td></tr>");
					print("<tr><td align=\"left\"></td><td align=\"left\">" . $lang_mybonus['text_not_enough_karma'] . "<br /><br /></td></tr></table>");
				}
			}echo "<script type='text/javascript'> alert('操作成功，具体信息请查看被盖在提示框下面的页面信息。点确定返回上个页面');history.go(-1) </script>";
		}
	}
}
stdfoot();
